Skip to content

Add mock HTTP server for integration tests#11

Merged
jonathan-kosgei merged 1 commit intoclaude/update-ipdata-api-AXInjfrom
claude/verify-all-tests-G2MNU
Feb 23, 2026
Merged

Add mock HTTP server for integration tests#11
jonathan-kosgei merged 1 commit intoclaude/update-ipdata-api-AXInjfrom
claude/verify-all-tests-G2MNU

Conversation

@jonathan-kosgei
Copy link
Copy Markdown
Collaborator

Summary

This PR introduces a mock HTTP server for testing the ipdata client library, eliminating the need for external API calls during test execution.

Key Changes

  • New MockIpdataServer class: A singleton HTTP server that handles GET and POST requests, mimicking the ipdata.co API behavior

    • Supports single IP lookups with full model, field selection, and sub-field queries
    • Implements bulk IP lookup endpoint
    • Validates API key on all requests
    • Loads test fixtures from JSON files for realistic responses
  • Test fixtures: Added 5 JSON fixture files representing real ipdata API responses for:

    • IPv4 addresses: 8.8.8.8, 1.1.1.1, 41.128.21.123
    • IPv6 addresses: 2001:4860:4860::8888, 2001:4860:4860::8844
  • Updated test classes: Modified all integration tests (AsnTest, CurrencyTest, FullModelTest, ThreatTest, TimeZoneTest, BulkTest, MultipleFieldsSelectionTest) to use the mock server instead of the live API endpoint

  • Build configuration: Changed nexus-staging-maven-plugin extension setting from true to false

Implementation Details

  • The mock server uses Java's built-in HttpServer and dynamically binds to an available port
  • Implements singleton pattern with thread-safe initialization
  • Handles URL path parsing to support IPv6 addresses (colons replaced with hyphens in fixture filenames)
  • Supports query parameters for field selection and API key validation
  • Returns appropriate HTTP status codes (401 for invalid API key, 404 for missing IPs/fields, 500 for errors)

https://claude.ai/code/session_01KxvyXRVVZaLrgTZshvsZY6

Replace live API calls with a local MockIpdataServer using JDK's
HttpServer. Tests now use fixture JSON data instead of requiring
an IPDATACO_KEY env var and network access to api.ipdata.co.

- Add MockIpdataServer with fixture-based HTTP responses
- Add JSON fixture files for all IPs used in tests
- Update all 7 integration test classes to use mock server
- Disable nexus-staging-maven-plugin extension (deploy-only)

https://claude.ai/code/session_01KxvyXRVVZaLrgTZshvsZY6
@jonathan-kosgei jonathan-kosgei merged commit 168bf44 into claude/update-ipdata-api-AXInj Feb 23, 2026
jonathan-kosgei added a commit that referenced this pull request Feb 23, 2026
Merge pull request #11 from ipdata/claude/verify-all-tests-G2MNU
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants